<?php defined('BASEPATH') OR exit('No direct script access allowed');


class Admin_role_model extends Base_model
{
	protected $_table_name  = 'admin_role';
    protected $_key_name    = 'id';
	
	public function __construct()
    {
        parent::__construct();
        
        log_message("debug","Admin_role_model is run.");
    }

    public function get_all($name = NULL)
    {
        if($name == NULL) return NULL;
        $this->select("admin_role.role_id as role_id,role.name as role_name,role.isroot as isroot");
        $this->join('admin','admin.id = admin_role.admin_id','left');
        $this->join('role','admin_role.role_id = role.id','left');

        $this->where("admin.name",$name);
        $this->where("admin.status",1);
        $this->where("admin.dtime",0);

        return $this->all();
    }

    /**
     * 通过
     */
    public function get_admin_all($id = 0)
    {
        if($id <= 0) return NULL;
        $this->select("admin_role.id as id,admin_role.admin_id as userId,role.id as roleId,role.name as name,role.isroot as isroot,role.remark as remark");
        $this->join('role','admin_role.role_id = role.id','left');
        $this->where("admin_role.admin_id",$id);
        $this->where("role.dtime",0);
        return $this->all();
    }

    public function delect_all_data($id = 0)
    {
        if($id <= 0) return false;
        return $this->delete(array("admin_id"=>$id));
    }

    public function add_all_data($data_arr = NULL)
    {
        if($data_arr == NULL) return false;

        $add_arr = NULL;
        foreach($data_arr as $val)
        {
            $zi["role_id"] = $val["role_id"];
            $zi["admin_id"] = $val["admin_id"];
            $zi["ctime"] = time();
            $add_arr[] = $zi;
        }
        //$data_arr["ctime"] = time();
        return $this->insert_batch($add_arr);
    }
	
	
}
/* End of file base_model.php */
/* Location: ./system/application/models/base_model.php */
